<template>
	<div class="confirm_address">
		<van-cell-group @click='address' v-if="addressinfo.id==undefined" style="text-align: center;">
			<van-empty description="请点击前往填写收货地址"/>
		</van-cell-group>
		<van-cell-group @click='address' v-if="addressinfo.id">
			<van-cell :title="addressinfo.name" is-link :value="addressinfo.tel" :label="addressinfo.address" />
		</van-cell-group>
	</div>
</template>

<script>
	import Vue from 'vue';
	import {
		Cell,
		CellGroup
	} from 'vant';
import { Empty } from 'vant';

Vue.use(Empty);
	Vue.use(Cell);
	Vue.use(CellGroup);
	export default {
		data() {
			return {
				addressinfo: [],
			}
		},
		methods: {
			address() {
				this.$router.push('/Address')
			}
		},
		mounted() {
			this.$http.post('/address/address', {
				u_id: this.$store.state.u_id
			}).then(res => {
				// console.log(JSON.parse(res.data.data[0].isDefault))
				for (var i = 0; i < res.data.data.length; i++) {
					if (res.data.data[i].isDefault) {
						if(sessionStorage.getItem('addressd')!=undefined){
							this.addressinfo = JSON.parse(sessionStorage.getItem('addressd'))
						}else{
							this.addressinfo = res.data.data[i]
							// console.log(this.addressinfo.length)
							sessionStorage.setItem('addressd',JSON.stringify(res.data.data[i]))
						}
					}
				}
			})
		}
	}
</script>

<style>
	.confirm_address {
		width: 100%;
		margin-top: 2.875rem;
	}
	.van-empty{
		padding: 0;
	}
	.van-empty__image{
		width: 40px;
		height: 40px;
	}
	
</style>
